import { createRouter, createWebHashHistory } from 'vue-router'
import localCache from '../utils/cache'
import type { RouteRecordRaw } from 'vue-router'
const routes: RouteRecordRaw[] = [
  {
    path: '/',
    redirect: '/main'
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/login/login.vue')
  },
  {
    path: '/main',
    name: 'main',
    component: () => import('@/views/main/main.vue')
  },
  {
    path: '/user',
    name: 'user',
    component: () => import('@/views/user/user.vue'),
    children: [
      {
        path: '/user/home',
        name: 'home',
        component: () => import('@/views/user/home/home.vue')
      },
      {
        path: '/user/message',
        name: 'message',
        component: () => import('@/views/user/message/message.vue'),
        children: [
          {
            path: '/user/message/comments',
            name: 'comments',
            component: () => import('@/views/user/message/cop/comments.vue')
          },
          {
            path: '/user/message/atme',
            name: 'atme',
            component: () => import('@/views/user/message/cop/atme.vue')
          },
          {
            path: '/user/message/notify',
            name: 'notify',
            component: () => import('@/views/user/message/cop/notify.vue')
          },
          {
            path: '/user/message/private',
            name: 'private',
            component: () => import('@/views/user/message/cop/private.vue')
          }
        ]
      },
      {
        path: '/user/level',
        name: 'level',
        component: () => import('@/views/user/level/level.vue')
      },
      {
        path: '/user/vip',
        name: 'vip',
        component: () => import('@/views/user/vip/vip.vue')
      },
      {
        path: '/user/setting',
        name: 'setting',
        component: () => import('@/views/user/setting/setting.vue'),
        children: [
          {
            path: '/user/setting/baseset',
            name: 'baseset',
            component: () => import('@/views/user/setting/baseset.vue')
          }
        ]
      }
    ]
  },
  {
    path: '/eason',
    name: 'eason',
    component: () => import('@/views/eason/eason.vue')
  },
  {
    path: '/music',
    name: 'music',
    component: () => import('@/views/music/music.vue'),
    children: [
      {
        path: '/music/topinfo',
        name: 'topinfo',
        component: () => import('@/views/music/topinfo.vue')
      },
      {
        path: '/music/musicTop',
        name: 'musicTop',
        component: () => import('@/views/music/musicTop.vue')
      },
      {
        path: '/music/mv',
        name: 'mv',
        component: () => import('@/views/music/mv.vue')
      },
      {
        path: '/music/musicvideo',
        name: 'musicvideo',
        component: () => import('@/views/music/musicvideo.vue')
      }
    ]
  },
  {
    path: '/other',
    name: 'other',
    component: () => import('@/views/other/other.vue')
  },
  {
    path: '/discover',
    name: 'discover',
    component: () => import('@/views/found/discover.vue')
  },
  {
    path: '/songInfo',
    name: 'songInfo',
    component: () => import('@/views/music/songInfo.vue')
  },
  {
    path: '/:pathMatch(.*)*',
    name: 'not-fount',
    component: () => import('@/views/not-found/404.vue')
  }
]

const router = createRouter({
  routes,
  history: createWebHashHistory()
})
router.beforeEach((to) => {
  if (to.path !== '/login') {
    const token = localCache.getCache('token')
    if (!token) {
      return '/login'
    }
  }
})
export default router
